package com.web.base.log.util;

import com.blue.jdbc.Page;
import com.web.base.log.message.SmsRequest;
import com.web.base.log.message.SmsResponse;
import com.web.base.log.model.Sms;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 短信日志转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 2017年11月21日
 */
public class SmsConvertor
{
	private SmsConvertor()
	{
	}
	
	public static Sms toSms(SmsRequest request)
	{
		if (request == null)
			return null;
		
		Sms sms = new Sms();
		sms.setId(request.getId());
		sms.setUserId(request.getUserId());
		sms.setMobile(request.getMobile());
		sms.setType(request.getType());
		sms.setParams(request.getParams());
		sms.setResult(request.getResult());
		sms.setSendTime(request.getSendTime());
		sms.setSeq(request.getSeq());
		return sms;
	}
	
	public static List<Sms> toSms(List<SmsRequest> requestList)
	{
		List<Sms> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (SmsRequest request : requestList)
		{
			list.add(toSms(request));
		}
		return list;
	}
	
	public static SmsResponse toResponse(Sms sms)
	{
		if (sms == null)
			return null;
		
		SmsResponse response = new SmsResponse();
		response.setId(sms.getId());
		response.setUserId(sms.getUserId());
		response.setMobile(sms.getMobile());
		response.setType(sms.getType());
		response.setParams(sms.getParams());
		response.setResult(sms.getResult());
		response.setSendTime(sms.getSendTime());
		response.setSeq(sms.getSeq());

		response.setUserName(sms.getUserName());
		return response;
	}
	
	public static List<SmsResponse> toResponse(List<Sms> list)
	{
		List<SmsResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Sms sms : list)
		{
			responseList.add(toResponse(sms));
		}
		return responseList;
	}
	
	public static Map<Integer, SmsResponse> toResponse(Map<Integer, Sms> map)
	{
		Map<Integer, SmsResponse> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, Sms> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<SmsResponse> toResponse(Page<Sms> page)
	{
		if (page == null)
			return null;
		
		Page<SmsResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
